package com.sms.user;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.sms.DB.OperateDB;

public class Teacher {
	private String tno;
	private String tname;
	private String sex;
	private String password;
	private int itemCount = 0;
	private List<String> students = null;//老师所带的学生姓名
	
	//初始化老师的信息
	public void init(Map map) {
		this.setTno((String)map.get("tno"));
		this.setTname((String)map.get("tname"));
		this.setSex((String)map.get("sex"));
		this.setPassword((String)map.get("passkey"));
		this.setStudents((String)map.get("tno"));
		this.setItemCount((String)map.get("tno"));
	}
	
	public int getItemCount() {
		return itemCount;
	}

	public void setItemCount(String tno) {
		String sql = "select count(*) as number from taskinfo " + 
				" where fromid = '" + tno +  "' " +
						" and task_type = '项目任务'" ;
		List<Map> list = new ArrayList<Map>();
		int count = 0;
		
		list = OperateDB.executeQuery(sql);
		if(list.size() > 0) {
			Map map = list.get(0);
			count = Integer.parseInt(map.get("number").toString());
		}
		
		this.itemCount = count;
	}

	public List<String> getStudents() {
		return students;
	}

	//设置指定编号的老师所带的学生姓名
	public void setStudents(String tno) {
		List<Map> list = new ArrayList<Map>();
		String sql = "select * from stuinfo where tno = '" + tno + "'" +
				" and isexist = '1' ";
		
		list = OperateDB.executeQuery(sql);
		if(list.size() > 0) {//老师带有学生时才初始化students对象
			students = new ArrayList<String>();
			for(int i=0; i<list.size(); i++) {
				Map map = list.get(i);
				String name = (String)map.get("sname");//获取学生的姓名
				students.add(name);
			}
		}
	}
	
	public String getTno() {
		return tno;
	}
	
	public void setTno(String tno) {
		this.tno = tno;
	}
	
	public String getTname() {
		return tname;
	}
	
	public void setTname(String tname) {
		this.tname = tname;
	}
	
	public String getSex() {
		return sex;
	}
	
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	
	
}
